import request from '@/router/axios';
import {
  fenExYuangettoFixed, getAppealTypes,
  getAudit_state_status,
  getData_source_status,
  getIs_have_bus_status, getIs_sup_payment,
  getLineName, getNotice_sate_status, getNoticeStates,getMappingStatusArray,
  getStationName, getSupp_state_status,supp_state_status,
  getSys_data_source_status, is_sup_payment, noticeStates,allStatus,getMappingStatus
} from "../../commonCheck";


export function getOption() {
  return {
    emptyBtn: false,
    editBtn: false,
    delBtn: false,
    addBtn: false,
    border: true,
    index: true,
    viewBtn:false,
    indexLabel: '序号',
    page: true,
    align: 'center',
    menuWidth: 150,
    menuAlign: 'center',
    selection: true,
    reserveSelection: false,
    column: [{label: "线路",width: 100, prop: "lineCode",search:true,searchslot:true,formatter: function(row, value , label, column){
        return getLineName(value);
      }},

      {label: "站点", width: 180,prop: "stationCode",search:true,searchslot:true,formatter: function(row, value , label, column){
          return getStationName(row.lineCode,value);
        }},
      {label: "收入日期", prop: "recordTime",type:'date',
        width: 90,format:'yyyy-MM-dd',valueFormat:'yyyy-MM-dd',search:true},
      {label: "差异金额", prop: "differenceAmount",formatter:function (row,v) {
          return fenExYuangettoFixed(row,'differenceAmount');
        }},
      {label: "售票员",width: 120, prop: "conductorPersonName",type:'select',search:true,searchslot:true},
      {label: "售票员工号", width: 130,prop: "conductorPersonCode"},
	  {label: "设备操作号", width: 130,prop: "equipmentNumber"},
      {label: "通知状态", prop: "noticeState",type:'select',search:false,hide:true,dicData:noticeStates(),formatter: function(row, value , label, column){
          return getNoticeStates(value);
        }},
      {label: "下发状态", prop: "sendStatus",type:'select',search:true,dicData:getMappingStatusArray('conductor_invalidticket_status')
      ,formatter: function(row, value , label, column){
        return getMappingStatus('conductor_invalidticket_status',value);
      }},
      {label: "下发时间", prop: "sendTime",type:'date',
      width: 160,format:'yyyy-MM-dd HH:mm:ss',valueFormat:'yyyy-MM-dd HH:mm:ss'},
      {label: "申诉状态", prop: "appealStatus",type:'select',search:true,dicData:allStatus['car_appeal_status'],
      formatter:function (row,v) {
        return getMappingStatus('car_appeal_status',v);
      }},
      {label: "申诉类型",width: 120, prop: "appealType",type:'select',search: true,
        dicUrl: '/admin/dict/type/spy_appeal_type',
        formatter:function (row,v) {
          return getAppealTypes(v);
        }
      },
      {label: "审批状态",width: 120, prop: "auditSate",type:'select',search:true,
        dicData:[{label:"待审批",value:"1"},{label:"审批通过",value:"2"},{label:"审批不通过",value:"3"}]
        ,formatter:function (row,v) {
          let state={'1':'待审批', '2':'审批通过','3':'审批不通过'};
          return state[v];
        }},
      {
        width: 120,
        "type": "select",
        "label": "数据来源",
        "prop": "dataSource",
        search:true,
        formatter:function(row, value , label, column){
          return value==1?'人工添加':value==0?'审核主页加入':'';
        },
        dicData: [{
          label: '审核主页加入',
          value: '0'
        }, {
          label: '人工添加',
          value: '1'
        }]
      },
      {
        width: 120,
        label: "补款状态",
        prop: "isSupPayment",
        type: 'select',
        search: true,
        hide:true,
        dicData: supp_state_status(),
        formatter: function (row, v) {
          return getSupp_state_status(v);
        }
      },


      {label: "最晚回复期限（天）",width: 160, prop: "replyPeriod"},
      {label: "申诉原因", prop: "appealReason", width:180},
      {label: "备注", prop: "remark", width:180},
      {label: "申诉回复", prop: "appealReply", width:180},
      {label: "审批人", prop: "approverName"},
      {label: "审批时间", width: 120,type:'date', format:'yyyy-MM-dd',valueFormat:'yyyy-MM-dd', prop: "approverTime"},
      {label: "附件", prop: "fileUrl",hide:true}
    ]
  }
}


export const tableOptionAdd = {
  border: true,
  index: true,
  align: "center",
  labelWidth: 160,
  submitBtn:false,
  emptyBtn:false,
  'column': [ 
    {
      label: "线路",
      prop: "lineCode",
      type: "select",
      labelWidth: 130,
      formslot: true,
      rules: [
        {
          required: true,
          message: "请选择线路",
          trigger: "blur"
        }
      ]
    },
    {
      label: "站点",
      prop: "stationCode",
      type: "select",
      labelWidth: 130,
      formslot: true,
      rules: [
        {
          required: true,
          message: "请选择站点",
          trigger: "blur"
        }
      ]
    }, {
      label: "售票员",
      prop: "conductorPersonName",
      labelWidth: 130,
      type: "select",
      formslot: true,
      rules: [
        {
          required: true,
          message: "请选择人员",
          trigger: "blur"
        }
      ]
    },
    {
      label: "售票员工号",
      prop: "conductorPersonCode",
      labelWidth: 130,
      type: "select",
      formslot: true,
    },
	 {
      label: "设备操作号",
      prop: "equipmentNumber",
      labelWidth: 130,
      type: "select",
      formslot: true,
    },
    {
      type: "select",
      label: "BOM编号",
      prop: "bomCode",
      labelWidth: 130,
      rules: [
        {
          required: true,
          message: "请输入BOM编号",
          trigger: "blur"
        }
      ],
      filterable: true,
      dicUrl: "/admin/dict/type/bom_code",
      multiple: true
    },
    {label: "收入日期", labelWidth: 130,prop: "recordTime",type:'date',
      valueFormat:'yyyy-MM-dd',search:true
    },
    {
      label: "差异金额",
      "type": "number",
      precision: 2,
      labelWidth: 130,
      prop: "differenceAmount",
      rules: [
        {
          required: true,
          message: "请输入差异金额",
          trigger: "blur"
        }
      ],
    },
    {label: "最晚回复期限（天）",labelWidth: 150, prop: "replyPeriod"},
  ]
}

/**
 * 列表
 * @param query
 */
export function getSwAuConductorNoticeList(query) {
  return request({
    url: '/check/check/getSwAuConductorNoticeList',
    method: 'post',
    params: query
  })
}

/**
 * 设置回复期限
 * @param query
 */
export function setReplyPeriod(query) {
  return request({
    url: '/check/check/setReplyPeriod',
    method: 'post',
    params: query
  })
}

/**
 * 审批申诉回复
 * @param query
 */
export function setAppealReply(query) {
  return request({
    url: '/check/check/setAppealReply',
    method: 'post',
    params: query
  })
}

/**
 * 审批申诉回复
 * @param query
 */
export function sendStatusUpdate(query) {
  return request({
    url: '/check/check/sendStatusUpdate',
    method: 'post',
    data: query
    //params: query
  })
}

/**
 * 单个审批
 * @param query
 */
export function approveData(query) {
  return request({
    url: '/check/check/setAppealReply',
    method: 'post',
    params: query
  })
}

export function addObj (obj) {
  if(typeof obj.bomCode !== 'string') {
    obj.bomCode = obj.bomCode.join(",");
  }
  return request({
    url: '/check/check/manuallyAdd',
    method: 'post',
    data:  JSON.parse(JSON.stringify(obj))
  })
}

export function putObj (obj) {
  if(typeof obj.bomCode !== 'string') {
    obj.bomCode = obj.bomCode.join(",");
  }
  return request({
    url: '/check/check/manuallyAudit',
    method: 'put',
    data: JSON.parse(JSON.stringify(obj))
  })
}

export function getObj (id) {
  return request({
    url: '/check/check/getById/' + id,
    method: 'get'
  })
}

export function delObj (query) {
  return request({
    url: '/check/check/removeByIds',
    method: 'get',
    params: query
  })
}